package com.ui;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import com.alumnos.Alumno;
import com.thoughtworks.xstream.XStream;
import com.util.Escritora;

public class WbNuevoAlumno extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField txtnombre;
	private JTextField txtEdad;
	public static final Alumno alumnos =new Alumno();
	private JTextField txtCurp;
	private JRadioButton rdbtnMasculino;
	private JRadioButton rdbtnFemenino;
	private JTextField txtPrimerosAuxilios;
	private JTextField txtAlergias;
	private JTextField txtColonia;
	private JTextField txtCelular;
	private JComboBox<?> comboBox;
	private JTextField txtDomicilio;
	private JTextField txtTelefono;
	private JTextField txtLugarFecha;
	private JTextField txtMedicamentos;
	private JTextField txtEnfermedades;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WbNuevoAlumno frame = new WbNuevoAlumno();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public WbNuevoAlumno() {
		final Escritora escritora = new Escritora();
		setTitle("Nuevo Alumno--Datos Generales");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 703, 377);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblNombre = new JLabel("Nombre");
		
		JLabel lblEdad = new JLabel("Edad");
		
		JLabel lblGnero = new JLabel("G\u00E9nero");
		
		txtnombre = new JTextField();
		txtnombre.setColumns(10);
		
		txtEdad = new JTextField();
		txtEdad.setColumns(10);
		
		rdbtnMasculino = new JRadioButton("Masculino");
		
		rdbtnFemenino = new JRadioButton("Femenino");
		
		JButton btnGuardar = new JButton("Guardar");
		btnGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				XStream xs = new XStream();
				xs.alias("Alumno", Alumno.class);
				/*PersistenceStrategy ps = new FilePersistenceStrategy(new File("/tmp"));
				List l = new XmlArrayList(ps);*/
				
			alumnos.setNombre(txtnombre.getText());
			alumnos.setEdad(txtEdad.getText());
			alumnos.setCURP(txtCurp.getText());
			alumnos.setDomicilio(txtDomicilio.getText());
			alumnos.setTelefono(txtTelefono.getText());
			alumnos.setTipoSangre(comboBox.getSelectedItem().toString());
			alumnos.setPrimerosAuxilos(txtPrimerosAuxilios.getText());
			alumnos.setLugarFechaNacimiento(txtLugarFecha.getText());
			alumnos.setColonia(txtColonia.getText());
			alumnos.setCelular(txtCelular.getText());
			alumnos.setEnfermedades(txtEnfermedades.getText());
			alumnos.setMedicamentos(txtMedicamentos.getText());
			alumnos.setAlergias(txtAlergias.getText());
								
				if(rdbtnMasculino.isSelected()==true){
					alumnos.setGenero("M");
				}else
					if(rdbtnFemenino.isSelected()==true){
						alumnos.setGenero("F");
					}
			
			System.out.println(
				        alumnos.getNombre()+ ","+alumnos.getEdad()+","+alumnos.getCURP()+","+alumnos.getGenero()+","+
						alumnos.getDomicilio()+","+alumnos.getTelefono()+","+alumnos.getTipoSangre()+","+alumnos.getPrimerosAuxilos()+","+
						alumnos.getLugarFechaNacimiento()+","+alumnos.getColonia()+","+alumnos.getCelular()+","+alumnos.getEnfermedades()+","+
						alumnos.getMedicamentos()+","+alumnos.getAlergias()
					);	
			
			try {
				/*escritora.escribir(alumnos.getNombre()+ "|"+alumnos.getEdad()+"|"+alumnos.getCURP()+"|"+alumnos.getGenero()+"|"+
						alumnos.getDomicilio()+"|"+alumnos.getTelefono()+"|"+alumnos.getTipoSangre()+"|"+alumnos.getPrimerosAuxilos()+"|"+
						alumnos.getLugarFechaNacimiento()+"|"+alumnos.getColonia()+"|"+alumnos.getCelular()+"|"+alumnos.getEnfermedades()+"|"+
						alumnos.getMedicamentos()+"|"+alumnos.getAlergias()
					);*/
				
				/*escritora.escribirXML("<alumno><nombre>"+alumnos.getNombre()+ "</nombre><edad>"+alumnos.getEdad()+"</edad><curp>"+alumnos.getCURP()+"</curp><genero>"+
						alumnos.getGenero()+"</genero><domicilio>"+alumnos.getDomicilio()+"</domicilio><telefono>"+alumnos.getTelefono()+"</telefono><tiposangre>"+
						alumnos.getTipoSangre()+"</tiposangre><primerosauxilios>"+alumnos.getPrimerosAuxilos()+"</primerosauxilios><lugarfechanacimiento>"+
						alumnos.getLugarFechaNacimiento()+"</lugarfechanacimiento><colonia>"+alumnos.getColonia()+"</colonia><celular>"+
						alumnos.getCelular()+"</celular><enfermedades>"+alumnos.getEnfermedades()+"</enfermedades><medicamentos>"+alumnos.getMedicamentos()+
						"</medicamentos><alergias>"+alumnos.getAlergias()+"</alergias></alumno>");*/
				escritora.escribirXML(xs.toXML(alumnos));
				
				
			} catch (IOException e1) {
				
				e1.printStackTrace();
			}
			
			dispose();
				
			}
		});
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		JLabel lblCurp = new JLabel("CURP");
		
		txtCurp = new JTextField();
		txtCurp.setColumns(10);
		
		JLabel lblDomicilio = new JLabel("Domicilio");
		
		txtDomicilio = new JTextField();
		txtDomicilio.setColumns(10);
		
		JLabel lblTelefono = new JLabel("Telefono");
		
		txtTelefono = new JTextField();
		txtTelefono.setColumns(10);
		
		JLabel lblTipoDeSangre = new JLabel("Tipo de Sangre");
		
		comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"O--", "O+", "A--", "A+", "B--", "B+", "AB--", "AB+"}));
		
		JLabel lblAlergias = new JLabel("Alergias");
		
		txtAlergias = new JTextField();
		txtAlergias.setColumns(10);
		
		JLabel lblPrimeros = new JLabel("Primeros auxilios en caso de tener una enfermedad:");
		
		txtPrimerosAuxilios = new JTextField();
		txtPrimerosAuxilios.setColumns(10);
		
		JLabel lblLugarfecha = new JLabel("Lugar/Fecha de Nacimiento");
		
		txtLugarFecha = new JTextField();
		txtLugarFecha.setColumns(10);
		
		JLabel lblColonia = new JLabel("Colonia");
		
		txtColonia = new JTextField();
		txtColonia.setColumns(10);
		
		JLabel lblCelular = new JLabel("Celular");
		
		txtCelular = new JTextField();
		txtCelular.setColumns(10);
		
		JLabel lblEnfermedades = new JLabel("Enfermedades");
		
		txtEnfermedades = new JTextField();
		txtEnfermedades.setColumns(10);
		
		JLabel lblMedicamentosProhibidos = new JLabel("Medicamentos Prohibidos");
		
		txtMedicamentos = new JTextField();
		txtMedicamentos.setColumns(10);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(20)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblEdad)
									.addGap(18)
									.addComponent(txtEdad, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblNombre)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(txtnombre, GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPane.createSequentialGroup()
											.addComponent(lblCurp)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(txtCurp, GroupLayout.PREFERRED_SIZE, 155, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED))
										.addGroup(gl_contentPane.createSequentialGroup()
											.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
												.addComponent(lblDomicilio)
												.addComponent(lblTelefono))
											.addPreferredGap(ComponentPlacement.RELATED)
											.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
												.addComponent(txtTelefono, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE)
												.addComponent(txtDomicilio, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)))
										.addGroup(gl_contentPane.createSequentialGroup()
											.addComponent(lblTipoDeSangre)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
										.addGroup(gl_contentPane.createSequentialGroup()
											.addComponent(lblPrimeros)
											.addPreferredGap(ComponentPlacement.RELATED))))))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblGnero)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(rdbtnFemenino)
								.addComponent(rdbtnMasculino))
							.addGap(176)))
					.addGap(40)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(txtPrimerosAuxilios, GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(lblColonia)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtColonia, GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(lblLugarfecha)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtLugarFecha, GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(lblCelular)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtCelular, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(lblEnfermedades)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtEnfermedades, GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(lblMedicamentosProhibidos)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtMedicamentos, GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(lblAlergias)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtAlergias, GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)))
					.addContainerGap())
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(512, Short.MAX_VALUE)
					.addComponent(btnGuardar)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnCancelar)
					.addGap(13))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(19)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNombre)
						.addComponent(txtnombre, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblLugarfecha)
						.addComponent(txtLugarFecha, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblEdad)
						.addComponent(txtEdad, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblColonia)
						.addComponent(txtColonia, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCurp)
						.addComponent(txtCurp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblCelular)
						.addComponent(txtCelular, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblDomicilio)
						.addComponent(txtDomicilio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblEnfermedades)
						.addComponent(txtEnfermedades, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblTelefono)
						.addComponent(txtTelefono, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblMedicamentosProhibidos)
						.addComponent(txtMedicamentos, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblTipoDeSangre)
							.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addComponent(lblAlergias)
						.addComponent(txtAlergias, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblPrimeros)
							.addGap(17)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblGnero)
								.addComponent(rdbtnMasculino))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(rdbtnFemenino))
						.addComponent(txtPrimerosAuxilios, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnGuardar)
						.addComponent(btnCancelar))
					.addContainerGap(21, Short.MAX_VALUE))
		);
		ButtonGroup genero = new ButtonGroup();
		genero.add(rdbtnFemenino);
		genero.add(rdbtnMasculino);

		contentPane.setLayout(gl_contentPane);
	}
}
